<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="embroot.css">
<TITLE>
Functionality overview: A closer look at QuickTest.java
</TITLE>
</HEAD>
<BODY >
<A HREF="embroot042.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="embroot041.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="embroot044.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc76">8.2</A>&nbsp;&nbsp;Functionality overview: A closer look at <TT>QuickTest.java</TT></H2>
<A NAME="sec:ji-closer-look"></A>
To give a broad overview of how the Java-ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> Interface works,
we take a closer look at <TT>QuickTest.java</TT>. Here is the Java source
code from <TT>QuickTest.java</TT>.
<PRE CLASS="verbatim">
import com.parctechnologies.eclipse.*;
import java.io.*;

public class QuickTest
{
  public static void main(String[] args) throws Exception
  {
    // Create some default Eclipse options
    EclipseEngineOptions eclipseEngineOptions = new EclipseEngineOptions();

    // Object representing the Eclipse engine
    EclipseEngine eclipse;

    // Connect the Eclipse's standard streams to the JVM's
    eclipseEngineOptions.setUseQueues(false);

    // Initialise Eclipse
    eclipse = EmbeddedEclipse.getInstance(eclipseEngineOptions);

    // Write a message
    eclipse.rpc("write(output, 'hello world'), flush(output)");

    // Destroy the Eclipse engine
    ((EmbeddedEclipse) eclipse).destroy();
  }
}

</PRE>
The structure of the <TT>main</TT> method in <TT>QuickTest.java</TT>
contains elements which will appear in any Java code which uses the
Java-ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> interface. These are as follows:<BR>
<BR>

<H4 CLASS="subsubsection">Always import the <TT>com.parctechnologies.eclipse</TT> package</H4>
Note the first line using <TT>import</TT>. We need to have this in every
Java source file which uses the Java-ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> Interface so that it can
load classes from the package.<BR>
<BR>

<H4 CLASS="subsubsection">Declare a reference to an <I>EclipseConnection</I> or an <I>EclipseEngine</I></H4>
<I>EclipseConnection</I> <A NAME="@default164"></A> and its
subinterface <I>EclipseEngine</I> <A NAME="@default165"></A> are Java
interfaces which contain the methods used when interacting with ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>.<BR>
<BR>

<H4 CLASS="subsubsection">Create an object which implements <I>EclipseConnection</I> or <I>EclipseEngine</I></H4>
There are a number of classes which implement these interfaces. In the case
of <TT>QuickTest.java</TT> we use an instance of <I>EmbeddedEclipse</I>
<A NAME="@default166"></A>. The initialisation of these implementing
classes varies from class to class. In the case of <I>EmbeddedEclipse</I>
initialisation is done by creating and configuring an <I>EclipseEngineOptions</I> object and using this in an invocation of the <I>EmbeddedEclipse</I> class' static method <TT>getInstance</TT>.<BR>
<BR>

<H4 CLASS="subsubsection">Interact with ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> using methods in the <I>EclipseConnection</I> or <I>EclipseEngine</I> interface</H4>
We interact with the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> engine by invoking methods on the object
which implements <I>EclipseConnection</I> <A NAME="@default167"></A> or <I>EclipseEngine</I> <A NAME="@default168"></A>. In the
case of <TT>QuickTest.java</TT> we invoke the <TT>rpc</TT><A NAME="@default169"></A> method, which causes
the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> to execute a goal, in this case one which simply prints a
message.<BR>
<BR>

<H4 CLASS="subsubsection">Terminate interaction with the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP></H4>
In order to clean up, after the Java program has finished interacting
with ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>, the interaction should be terminated. Like
initialisation, how this termination is done varies among the classes
which implement the <I>EclipseConnection</I> and <I>EclipseEngine</I>
interfaces. In the case of <TT>QuickTest.java</TT>, termination is done
by invoking the <TT>destroy</TT> method on the <I>EmbeddedEclipse</I>
object.<A NAME="@default170"></A><BR>
<BR>
<HR>
<A HREF="embroot042.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="embroot041.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="embroot044.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
